package tech.aistar.exception;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 本类用来演示: 全局异常处理器
 *
 * @author: success
 * @date: 2021/5/10 10:33 上午
 */
@ControllerAdvice
public class ExceptionGlobal {

    /**
     * 对所有的未知异常进行统一处理.
     * @param model
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public String test01(Model model, Exception e){
        model.addAttribute("error","异常");
        return "error/error";
    }

    /**
     * 如果出现了MyException - 进入到此处
     * @param model
     * @param e
     * @return
     */
    @ExceptionHandler(MyException.class)
    public String test02(Model model, Exception e){
        model.addAttribute("error",e.getMessage());
        return "error/error";
    }
}
